//
//  UILabelExtension.swift
//  zhende
//
//  Created by 陆文宇 on 2017/6/11.
//  Copyright © 2017年 chenliang. All rights reserved.
//

import UIKit

extension UILabel {
    
    /**
     *  通过给定的字符串初始化合适大小的UILabel
     *
     *  - Parameters:
     *      - frame:   初始化位置和大小，height是预设高度
     *      - aFont:   字符串的字体
     *      - aString: 给定的字符串
     *
     *  - Returns: UILabel实例对象
     */
    convenience init(frame: CGRect, aFont: UIFont = UIFont.systemFont(ofSize: 17), aString: String) {
        let rect: CGRect = NSString(string: aString).boundingRect(with: frame.size, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: aFont], context: nil)
        
        self.init(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: rect.size.height + 5))
        
        textColor = .darkGray
        font = aFont
        numberOfLines = 0
        text = aString
    }
    
}
